package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.MovieBean;
import com.project.bean.PageBean;
import com.project.service.IMovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("movie")
public class MovieController {
    @Autowired
    private IMovieService movieService;
    /**
     * 条件分页查询可购买的电影票
     * @param pageNO 页码
     * @param name 电影名称
     * @param storeName 电影院名称
     * @param matches 场次
     * @param rowNum 排号
     * @return 分页对象
     */
    @RequestMapping("cutByItem")
    public PageBean<MovieBean> cutByItem(Integer pageNO, String name, String storeName, String matches, String rowNum){
        IPage<MovieBean> iPage = movieService.cutByItem(pageNO, name, storeName, matches, rowNum);
        PageBean<MovieBean> pageBean = new PageBean<>();
        pageBean.setRows(iPage.getRecords());
        pageBean.setTotalCount((int) iPage.getTotal());
        return pageBean;
    }

    /**
     * 买票（修改状态）
     * @param movie 电影票对象
     * @return 是否成功
     */
    @RequestMapping("buyMovie")
    public String buyMovie(MovieBean movie){
        movieService.buyMovie(movie);
        return "ok";
    }

    @RequestMapping("findById/{movieId}")
    public MovieBean findById(@PathVariable("movieId") Integer movieId){
        return movieService.findById(movieId);
    }
}
